<?php
/*******************************************************************************
Rd_Ils_Abstract
Abstract Implementation of ILS

Created by Jason White (jbwhite@emory.edu)
Modified by NCSU Libraries, NC State University. Modifications by Troy Hurteau (libraries.opensource@ncsu.edu).

This file is part of NCSU's distribution of ReservesDirect. This version has not been downloaded from Emory University
or the original developers of ReservesDirect. Neither Emory University nor the original developers of ReservesDirect have authorized
or otherwise endorsed or approved this distribution of the software.

Copyright (c) 2004-2006 Emory University, Atlanta, Georgia.

Licensed under the NCSU ReservesDirect License, Version 2.0 (the "License"); 
you may not use this file except in compliance with the License. You may obtain a copy of the full License at
 http://www.lib.ncsu.edu/it/opensource/

ReservesDirect is distributed in the hope that it will be useful,
but is distributed "AS IS" and WITHOUT ANY WARRANTY, without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE, and without any warranty as to non-infringement of any third
party's rights. See the License for the specific language governing permissions and limitations under the License.

The original version of ReservesDirect is located at:
http://www.reservesdirect.org/

This version of ReservesDirect, distributed by NCSU, is located at:
http://code.google.com/p/reservesdirect-ncsu/

*******************************************************************************
This is an abstract class for documentation on php abstract classes see
http://www.php.net/abstract

All fuctions marked as abstract must be implemented in derived classes
*******************************************************************************/
require_once(APPLICATION_PATH . '/lib/Rd/Ils/Exception.php');

abstract class Rd_Ils_Abstract
{
	public $_ilsName;	
	public $_view;
	protected $_reservable_formats = array();
	
	protected $create_reserve_script;
	protected $holdings_script;	
	
	public function __construct($basePath = NULL) //#TODO maybe deprecate this parameter
	{
//		$this->_view = new Zend_View();
//		$this->_view->setBasePath($basePath);	
		
		$this->setILSName();
		$this->setReservableFormats();
	}

    /**
     * Set the local name of ILS
     *
     * @param  void
     * @return void
    */		
	protected abstract function setILSName();  
	
    /**
     * Get the local name of ILS
     *
     * @param  void
     * @return void
    */		
	public function getName(){
		return 'The ILS';
	}

    /**
     * Get the user's ils username
     *
     * @param void
     * @return string
     */
    public function getILSUserID($user){
        return $user->getUsername();
    }

    /**
     * Get the user's ils name (ex: 'John Smith')
     *
     * @param void
     * @return string
     */
    public function getILSUserName($user){
        return $user->getName(false);
    }

    /**
     * Load Array of items types which may be placed on reserve
     *
     * @param  void
     * @return void
    */		
	protected abstract function setReservableFormats();
	public function getReserveableFormats() { return $this->_reservable_formats; }

	/**
     * Determine if passed format is reservable
     *
     * @param  string format
     * @return boolean
     * 
     * This function may be overloaded if needed
    */		
	public function isReservableFormat($format)
	{
		return in_array($format, $this->_reservable_formats);
	}
			
    /**
     * Return HTML form to collect necessary information to create reserve
     *    preferred method: render template file found in view directory
     * 	  secondary method: return HTML as string
     *
     * @param  void
     * @return HTML form
    */			
	public abstract function displayReserveForm();	
	
    /**
     * Return Array containing Holding data from ILS
     *
     * @param  void
     * @return Array
    */				
	public abstract function getHoldings($key, $keyType = 'barcode');
	
    /**
     * Set reserve in ILS
     *
     * @param  void
     * @return RD_Ils_Result
    */				
	public abstract function createReserve($request, $reserve);

    /**
     * Search ILS for items
     *
     * @param  String $searchField
     * @return RD_Ils_Result
    */	
	public abstract function search($search_field, $search_term);

	/**
	 * 
	 * indicates if the ILS can flag items as On Reserve
	 * @return bool
	 */
	public function supportsReserveRecords(){
		return false;
	}
	
	/**
	 * 
	 * indicates if the ILS can lookup items base on an identifier
	 * @return bool
	 */
	public function supportsItemLookup()
	{
		return false;
	}
	
	/**
	 * indicates if the ILS has a facility to providing a sortable shelving key for items
	 * @return bool
	 */
	public function supportsItemSorting()
	{
		return false;
	}
	
	public function getShelvingKey($key, $keyType = Rd_Ils::ITEM_CONTROL_KEY)
	{
		return $this->supportsItemSorting() ? $this->_getShelvingKey($key, $keyType) : '';
	}
	
	public function sortItems($keys, $keyType = Rd_Ils::ITEM_CONTROL_KEY)
	{
		return $this->supportsItemSorting() ? $this->_sortItems($keys, $keyType) : $keys;
	}
	
	public function getCatalogUrlFor($key, $keyType)
	{
		return ''; 
	}
	
	public static function filterIdentifier($identifier, $type = 'title')
	{
		return $identifier;
	}
}